package com.audaque.springboot.foshanupload.web.consuldemo.filter;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.web.reactive.filter.OrderedWebFilter;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;

/**
 * @author zgb
 * @desc ...
 * @date 2023-08-03 17:15:28
 */

@Component
@Slf4j
@RequiredArgsConstructor
public class SubscriberContextFilter implements OrderedWebFilter {
    private static final String REQUEST_TIME_BEGIN = "requestTimeBegin";

    @Override
    public int getOrder() {
        return -200;
    }

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
        return chain.filter(exchange).subscriberContext(ctx -> {
            return ctx.put("key", Mono.subscriberContext().map(ctx1 -> ctx1.get("key")));
        });
    }
}
